import type { MockMethod } from 'vite-plugin-mock';
import PurchaseList from '../json/purchase_list.json';
import PurchaseDetail from '../json/purchase_detail.json';
import PurchaseSettlementDetails from '../json/purchase_settlement_details.json';
import PurchaseDeductionItems from '../json/purchase_deduction_items.json';

const apis: MockMethod[] = [
  {
    // 对账单列表
    url: '/mock/getPurchaseList',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult => {
      const { billClass = undefined, billType = undefined, beginDate = undefined, endDate = undefined } = options.body;
      if (!billClass || !beginDate || !billType || !endDate) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      if (billClass === '2' && billType === '2') {
        return {
          code: 1000,
          message: '未获取到对账单，请重试！',
          data: null
        };
      }
      const data = PurchaseList;
      return {
        code: 200,
        message: 'ok',
        data
      };
    }
  },
  {
    // 对账单详情
    url: '/mock/getPurchaseDetail',
    method: 'post',
    response: (): Service.MockServiceResult => {
      const data = PurchaseDetail;
      return {
        code: 200,
        message: 'ok',
        data
      };
    }
  },
  {
    // 对账单详情_结算明细
    url: '/mock/getPurchaseSettlementDetails',
    method: 'post',
    response: (): Service.MockServiceResult => {
      const data = PurchaseSettlementDetails;
      return {
        code: 200,
        message: 'ok',
        data
      };
    }
  },
  {
    // 对账单详情_扣款项目
    url: '/mock/getPurchaseDeductionItems',
    method: 'post',
    response: (): Service.MockServiceResult => {
      const data = PurchaseDeductionItems;
      return {
        code: 200,
        message: 'ok',
        data
      };
    }
  },
  {
    // 批量提交对账单
    url: '/mock/submitPurchaseList',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult => {
      const { purchaseList = [] } = options.body;
      if (purchaseList.length === 0) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      return {
        code: 200,
        message: '对账单提交成功！',
        data: {
          total: '10'
        }
      };
    }
  },
  {
    // 获取对账单
    url: '/mock/getNewBill',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult => {
      const { billClass = undefined, billType = undefined, beginDate = undefined, endDate = undefined } = options.body;
      if (!billClass || !billType || !beginDate || !endDate) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      if (billClass === '2' && billType === '2') {
        return {
          code: 1000,
          message: '未获取到对账单，请重试！',
          data: null
        };
      }
      return {
        code: 200,
        message: '获取账单成功！',
        data: {
          billId: 'JX-INVJS2022062700671'
        }
      };
    }
  },
  {
    // 批量删除明细账单
    url: '/mock/deleteDetailBills',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult => {
      const { entryIds = undefined } = options.body;
      if (!entryIds) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      if (entryIds === '100039,123,124,125,2974274') {
        return {
          code: 1000,
          message: '对账单已删除！',
          data: null
        };
      }
      return {
        code: 200,
        message: '删除成功！',
        data: {
          A_JSAMOUNT: 13381.4,
          A_CYTAXAMT: 0,
          A_CYAMOUNT: 0,
          A_KPAMOUNT: 13381.4,
          A_JSKKAMOUNT2: 0,
          A_JSKKAMOUNT3: 0,
          A_KKAMOUNT: 0,
          A_JSKKAMOUNT1: 0,
          A_APAMOUNT: 13381.4,
          A_CYNOTAXAMT: 0,
          A_AMOUNT: 13381.4,
          A_LASTUPDATEDATE: 2
        }
      };
    }
  },
  {
    // 保存/提交对账单
    url: '/mock/submitBill',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult<any> => {
      const { billId = undefined, billDate = undefined, billRemark = undefined, type = 0 } = options.body;
      if (!billId || !billDate || !type) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      // 有删除
      if (billId === 'JX-INVJS202206270068') {
        return {
          code: 200,
          message: `对账单${type === '0' ? '保存' : '提交'}成功！`,
          data: {
            billId,
            detail: {
              A_BILLDATE: billDate,
              A_REMARK: billRemark,
              A_JSAMOUNT: 65432.1,
              A_CYTAXAMT: 1.1,
              A_CYAMOUNT: 0,
              A_KPAMOUNT: 3381.4,
              A_JSKKAMOUNT2: 110,
              A_JSKKAMOUNT3: 110,
              A_KKAMOUNT: 220,
              A_JSKKAMOUNT1: 330,
              A_APAMOUNT: 3381.4,
              A_CYNOTAXAMT: 330,
              A_AMOUNT: 3381.4,
              A_LASTUPDATEDATE: 2
            },
            deleteIds: [123, 124, 125]
          }
        };
      }
      // 临时价
      if (billId === 'JX-INVJS202206270069') {
        return {
          code: 1000,
          message: `该单据都是临时价，已删除！`,
          data: {
            billId,
            detail: null,
            deleteIds: []
          }
        };
      }
      return {
        code: 200,
        message: `对账单${type === '0' ? '保存' : '提交'}成功！`,
        data: {
          billId,
          detail: null,
          deleteIds: []
        }
      };
    }
  },
  {
    // 刷新结算价
    url: '/mock/refreshPrice',
    method: 'post',
    response: (options: Service.MockOption): Service.MockServiceResult => {
      const { billId = undefined } = options.body;
      if (!billId) {
        return {
          code: 1000,
          message: '参数校验失败！',
          data: null
        };
      }
      return {
        code: 200,
        message: '刷新结算价成功！',
        data: {
          A_JSAMOUNT: 12345.6,
          A_CYTAXAMT: 0,
          A_CYAMOUNT: 0,
          A_KPAMOUNT: 3381.4,
          A_JSKKAMOUNT2: 0,
          A_JSKKAMOUNT3: 0,
          A_KKAMOUNT: 0,
          A_JSKKAMOUNT1: 0,
          A_APAMOUNT: 3381.4,
          A_CYNOTAXAMT: 0,
          A_AMOUNT: 3381.4,
          A_LASTUPDATEDATE: 2
        }
      };
    }
  }
];

export default apis;
